from kivy.app import App
from kivy.core.text import DEFAULT_FONT, LabelBase
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button

from kivy_cust.ConfigComm import ConfigComm
from kivy_cust.MulitipleDropDown import MultiSelectDropDown

LabelBase.register(DEFAULT_FONT, ConfigComm.FONT_SIMKAI)


class MyLayout(BoxLayout):
    def drop_down_click(self, item):
        print(f'点击项：{item.text} | {item.state}')
        # 修改点击项的状态
        item.state = 'down' if item.state == 'normal' else 'normal'

        # 将已选择的项显示到文本框
        multi_text = ', '.join([btn.text for btn in self.ids.dropdown.children[0].children if
                                isinstance(btn, Button) and btn.state == 'down'])
        multi_text = f'{multi_text if multi_text else "请选择门票场次"}'
        self.ids.ground_ids.text = multi_text
        print(f'已选项：{multi_text}')

    def add_tickets_option(self):
        print('==>> add_tickets_option')
        # self.ids.dropdown3.options.append('666')
        self.dropdown2.options.append('666')
    def select_tickets_option(self):
        print('==>> select_tickets_option')
        # self.ids.dropdown3.selected_options.append('666')
        self.dropdown2.selected_options.append('666')

class MyApp(App):
    def build(self):
        self.title = '下拉框'
        self.icon = 'pixel_cat.png'  # 设置程序图标
        root = Builder.load_file('99-DropDown.kv')

        options = ['场次一', '场次二', '场次三', '场次四']
        dropdown2 = MultiSelectDropDown(main_button=root.ids.dropdown2_text, options=options, selected_options=['场次二', '场次三'])
        root.dropdown2 = dropdown2

        return root


if __name__ == '__main__':
    MyApp().run()
